package com.bing.dao;

import com.bing.bean.weixin.Article;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by kaibb on 2014/12/6.
 */
@Repository
public interface ArticleDao {
    @Select("select a.* from Article a , MessageArticle m where a.id=m.articleId and m.msgId=#{id}")
    List<Article> getArticlesByMsgId(int id);

    @Insert("insert into Article(title,description,picUrl,url,content,cTime,zan,du,keywords,tags) " +
            "values(#{title},#{description},#{picUrl},#{url},#{content},#{cTime},#{zan},#{du},#{keywords},#{tags})")
    @Options(useGeneratedKeys = true)
    int createArticle(Article article);

    @Delete("delete from Article where id=#{id}")
    void deleteArticle(long id);

    @Update("update Article set title=#{title},description=#{description},picUrl=#{picUrl},url=#{url},content=#{content},tags=#{tags},zan=#{zan},du=#{du},keywords=#{keywords},uTime=#{uTime} where id=#{id}")
    void updateArticle(Article article);

    @Select("select * from Article")
    List<Article> getAll();

    @Select("select * from Article where id=#{id}")
    Article findById(int id);
}
